﻿using Sustainalytics.ESG.Entities;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.CRT.Synchronization
{
    public class FocusedRatingsIndustryListManager
    {
        private readonly IEnumerable<RPCorporateScore> fullEsgCorporateScore;

        public FocusedRatingsIndustryListManager(IEnumerable<RPCorporateScore> fullEsgCorporateScore)
        {
            this.fullEsgCorporateScore = fullEsgCorporateScore;
        }

        public RPCorporateScore[] GetIndustryPeersForCompany(RPCompanyESGComputationResult focusedRatingsScore, string focusedRatingsCompanyName)
        {
            var tempScore = new RPCorporateScore { CompanyId = focusedRatingsScore.Id, CompanyName = focusedRatingsCompanyName, Score = focusedRatingsScore.OverallPerformance.Score };
            var tempList = fullEsgCorporateScore.ToList();
            tempList.Add(tempScore);

            return PeerOrderingPolicy.GetScores(tempList, x => x.Score);
        }
    }
}